home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.08 Aug 90 / Test Object Source / CWaveDoc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-31  |  3.5 KB  |  168 lines  |  [TEXT/KAHL]

  1. /****
  2.  * CWaveDoc.c
  3.  *
  4.  *    © Symantec - USE FOR TEST ONLY! - (stripped down from Starter appl)
  5.  *
  6.  ****/
  7.  
  8. #include <Global.h>
  9. #include <Commands.h>
  10. #include <CApplication.h>
  11. #include <CBartender.h>
  12. #include <CDataFile.h>
  13. #include <CDecorator.h>
  14. #include <CDesktop.h>
  15. #include <CError.h>
  16. #include <CPanorama.h>
  17. #include <CPane.h>
  18.  
  19. #include "CWaveDoc.h"
  20. #include "CWavePanel.h"
  21.  
  22.  
  23. #define    mainWindID        500        /* Resource IDs */
  24. #define mainPaneID        500
  25.  
  26. #define panelPaneID        501
  27. #define scopePaneType    'Pane'
  28. #define scopePaneID        502
  29.  
  30.  
  31. extern    CApplication *gApplication;    /* The application */
  32. extern    CBartender    *gBartender;    /* The menu handling object */
  33. extern    CDecorator    *gDecorator;    /* Window dressing object    */
  34. extern    CDesktop    *gDesktop;        /* The enclosure for all windows */
  35. extern    CBureaucrat    *gGopher;        /* The current boss in the chain of command */
  36. extern    OSType        gSignature;        /* The application's signature */
  37. extern    CError        *gError;        /* The global error handler */
  38.  
  39. /* IWaveDoc */
  40.  
  41. void CWaveDoc::IWaveDoc(CBureaucrat *aSupervisor, Boolean printable)
  42.  
  43. {
  44.     CDocument::IDocument(aSupervisor, printable);
  45. }
  46.  
  47.  
  48. /* NewFile */
  49.  
  50. void CWaveDoc::NewFile(void)
  51.  
  52. {
  53.     BuildWindow(NULL);
  54.     itsWindow->Select();
  55. }
  56.  
  57.  
  58. /* OpenFile */
  59.  
  60. void CWaveDoc::OpenFile(SFReply *macSFReply)
  61.  
  62. {
  63.     CDataFile    *theFile;
  64.     Handle        theData;
  65.     Str63        theName;
  66.     OSErr        theError;
  67.  
  68.     theFile = new(CDataFile);
  69.     theFile->IDataFile();
  70.     theFile->SFSpecify(macSFReply);
  71.     itsFile = theFile;
  72.     theError = theFile->Open(fsRdWrPerm);
  73.     if (!gError->CheckOSError(theError)) {
  74.         Dispose();
  75.         return;
  76.     }
  77.     gApplication->RequestMemory(FALSE, FALSE);
  78.     theFile->ReadAll(&theData);
  79.     if (theData == NULL) {
  80.         gError->CheckOSError(MemError());
  81.         Dispose();
  82.         return;
  83.     }
  84.     BuildWindow(theData);
  85.     DisposHandle(theData);
  86.     itsFile->GetName(theName);
  87.     itsWindow->SetTitle(theName);
  88.     itsWindow->Select();
  89. }
  90.  
  91.  
  92.  
  93. /** BuildWindow, used by NewFile() and OpenFile(), display theData  **/
  94.  
  95. void CWaveDoc::BuildWindow (Handle theData)
  96. {
  97.     CPane        *mainPane;
  98.     CWavePanel    *panelPane;
  99.     CPane        *scopePane;
  100.  
  101.     Rect r;
  102.  
  103.     itsWindow = new(CWindow);                    /*create main window*/
  104.     itsWindow->IWindow(mainWindID,FALSE,gDesktop,this);
  105.  
  106.     mainPane = new(CPane);                        /*create main pane*/
  107.     mainPane->IViewRes('Pane',mainPaneID,itsWindow,this);
  108.     mainPane->FitToEnclosure(TRUE,TRUE);
  109.  
  110.     mainPane->GetFrame(&r);                        /*adjust window to pane*/
  111.     topLeft(r) = botRight(r);                    /*min size = max size*/
  112.     itsWindow->SetSizeRect(&r);
  113.     itsWindow->ChangeSize(r.right,r.bottom);
  114.  
  115.     panelPane = new(CWavePanel);                /*create control panel pane*/
  116.     panelPane->IWavePanel(panelPaneID,mainPane,this);
  117.                         
  118.     scopePane = new(CPane);                        /*create oscilloscope pane*/
  119.     scopePane->IViewRes(scopePaneType,scopePaneID,mainPane,this);
  120.  
  121.     itsMainPane = mainPane;                        /*print: all panes*/
  122.     itsGopher = panelPane;                        /*send cmds to ctrl panel*/
  123.     
  124.     gDecorator->PlaceNewWindow(itsWindow);        /*ok, place window*/
  125. }
  126.  
  127.  
  128. /* DoSave */
  129.  
  130. Boolean CWaveDoc::DoSave(void)
  131.  
  132. {
  133.     if (itsFile == NULL)
  134.         return(DoSaveFileAs());
  135.     else {
  136.         dirty = FALSE;                    /* Document is no longer dirty        */
  137.         gBartender->DisableCmd(cmdSave);
  138.         return(TRUE);                    /* Save was successful                */
  139.     }
  140. }
  141.  
  142.  
  143. /* DoSaveAs */
  144.  
  145. Boolean CWaveDoc::DoSaveAs(SFReply *macSFReply)
  146.  
  147. {
  148.     if (itsFile != NULL)
  149.         itsFile->Dispose();
  150.     itsFile = new(CDataFile);
  151.     ((CDataFile *)itsFile)->IDataFile();
  152.     itsFile->SFSpecify(macSFReply);
  153.     itsFile->CreateNew(gSignature, 'TEXT');
  154.     itsFile->Open(fsRdWrPerm);
  155.     
  156.     itsWindow->SetTitle(macSFReply->fName);
  157.  
  158.     return( DoSave() );
  159. }
  160.  
  161.  
  162. /* DoRevert */
  163.  
  164. void CWaveDoc::DoRevert(void)
  165.  
  166. {
  167. }
  168.